package com.fixme4trade.view;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import com.fixme4trade.business.ProductBC;
import com.fixme4trade.domain.Product;
import br.gov.frameworkdemoiselle.annotation.NextView;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractListPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;

@ViewController
@NextView("/auth/product_edit.xhtml")
@PreviousView("/auth/product_list.xhtml")
public class ProductListMB extends AbstractListPageBean<Product, Long> {

	private static final long serialVersionUID = 1L;

	@Inject
	private ProductBC bc;

	@Override
	protected List<Product> handleResultList() {
		return this.bc.findAll();		
	}

	@Transactional
	public String deleteSelection() {
		boolean delete;
		for (Iterator<Long> iter = getSelection().keySet().iterator(); iter.hasNext();) {
			Long id = iter.next();
			delete = getSelection().get(id);

			if (delete) {
				bc.delete(id);
				iter.remove();
			}
		}
		return getPreviousView();
	}
	
	public List<Product> getProductsOwnedByUser(){
		List<Product> list = new ArrayList<Product>();
		
		return list;
	}

}